{extend name="base" /}
{block name="css"}{/block}
{block name="body"}
<form action="{:request()->url()}" class="layui-form" method="post" enctype="">
  <div class="layui-tab layui-tab-brief" >
      <ul class="layui-tab-title">
          <li class="layui-this">通用信息</li>
          <li>详情描述</li>
          <li>商品规格</li>
          <li>其他信息</li>
          <li>商品相册</li>
          <li>供应商</li>
      </ul>
      <div class="layui-tab-content" style="height: 100px;">
        <!-- 通用信息 start--> 
        <div class="layui-tab-item layui-show">
          <div class="layui-form-item">
            <label class="layui-form-label">商品名称</label>
            <div class="layui-input-block">
              <input type="text" name="name" value="{$data.name|default=''}" lay-verify="required" placeholder="请输入商品名称" autocomplete="off" class="layui-input">
            </div>
          </div>
          <div class="layui-form-item">
            <div class="layui-inline">
              <label class="layui-form-label">商品编号</label>
              <div class="layui-input-inline">
                <input type="tel" name="good_sn" value="{$data.good_sn|default=''}" lay-verify="required" placeholder="请输入商品编号" autocomplete="off" class="layui-input">
              </div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label">商品分类</label>
              <div class="layui-input-inline">
                <select name="cate_id" lay-verify="required" lay-search="">
                  <option value="">请选择商品分类</option>
                  {volist name="cate" id="val"}
                  <optgroup label="{$val.name}">
                    {volist name="$val.children" id="v"}
                    <option value="{$v.id}" {if condition="isset($data) and $data.cate_id eq $v.id"}selected{/if}>{$v.name}</option>
                    {/volist}
                  </optgroup>
                  {/volist}
                </select>
                <!-- <select name="cate_id" lay-verify="required" lay-search="">
                  <option value="">请选择商品分类</option>
                  {volist name="cate" id="v"}
                  <option value="{$v.id}" {if condition="isset($data) and $data.cate_id eq $v.id"}selected{/if}>{$v.name}</option>
                  {/volist}
                </select> -->
              </div>
            </div>
          </div>
          <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">商品描述</label>
            <div class="layui-input-block">
              <textarea placeholder="请输入商品描述" name="goods_brief" class="layui-textarea">{$data.goods_brief|default=''}</textarea>
            </div>
          </div>
          <div class="layui-form-item">
            <div class="layui-inline">
              <label class="layui-form-label">本店售价</label>
              <div class="layui-input-inline">
                <input type="tel" name="shop_price" value="{$data.shop_price|default=0}" lay-verify="required" placeholder="￥" autocomplete="off" class="layui-input">
              </div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label">市场售价</label>
              <div class="layui-input-inline">
                <input type="text" name="market_price" value="{$data.market_price|default=0}" lay-verify="required" placeholder="￥" autocomplete="off" class="layui-input">
              </div>
            </div>
          </div>
          <div class="layui-form-item">
            <div class="layui-inline">
              <label class="layui-form-label">商品库存</label>
              <div class="layui-input-inline">
                <input type="tel" name="stock" value="{$data.stock|default=1}" lay-verify="required" placeholder="请输入库存" autocomplete="off" class="layui-input">
              </div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label">供货/成本价</label>
              <div class="layui-input-inline">
                <input type="text" name="supp_price" value="{$data.supp_price|default=0}" lay-verify="required" placeholder="请输入供货/成本价" autocomplete="off" class="layui-input">
              </div>
            </div>
          </div>
          <div class="layui-form-item">
            <div class="layui-inline">
              <label class="layui-form-label">赠送积分</label>
              <div class="layui-input-inline">
                <input type="tel" name="give_integral" value="{$data.give_integral|default=0}" lay-verify="required" placeholder="请输入赠送积分" autocomplete="off" class="layui-input">
              </div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label">赠送成长值</label>
              <div class="layui-input-inline">
                <input type="text" name="give_growth" value="{$data.give_growth|default=0}" lay-verify="required" placeholder="请输入赠送成长值" autocomplete="off" class="layui-input">
              </div>
            </div>
          </div>
        </div>
        <!-- 通用信息 end--> 
        <!-- 商品详情 start--> 
        <div class="layui-tab-item">
          <div class="layui-form-item">
            <div class="layui-input-block">
              <textarea name="content" placeholder="请输入详情内容" id="editor" style="height:400px;">{$data.content|default=''}</textarea>
            </div>
          </div>
        </div>
        <!-- 商品详情 end--> 
        <!-- 属性与规格 start--> 
        <div class="layui-tab-item">
          <div class="layui-form-item">
            <div class="layui-inline">
              <label class="layui-form-label">商品模型</label>
              <div class="layui-input-block">
                <select name="group_id" lay-search="">
                  <option value="0">请选择商品模型</option>
                  {volist name="group" id="v"}
                  <option value="{$v.id}" {if condition="isset($data) and $data.group_id eq $v.id"}selected{/if}>{$v.name}</option>
                  {/volist}
                </select>
              </div>
              <div class="layui-input-block" id="attr_id">
              {notempty name="$sku"}
                {volist name='sku' id='v'}
                <input type="checkbox" name="sku_id[]" value="{$v.id}" title="{$v.name}" {in name="$v.id" value="$data.sku_id"} checked{/in}>
                {/volist}
              {else}
                <input type="hidden" name="sku_id" value="0" title="" checked>
              {/notempty}
              </div>
            </div>
          </div>
        </div>
        <!-- 属性与规格 end-->
        <!-- 其他信息 start--> 
        <div class="layui-tab-item">
          <div class="layui-form-item">
            <label class="layui-form-label">推荐</label>
            <div class="layui-input-block">
              <input type="hidden" name="is_best" value="0">
              <input type="checkbox" name="is_best" value="1" title="精品" {if condition="isset($data.is_best) AND $data.is_best eq 1"}checked{/if}>
              <input type="hidden" name="is_new" value="0">
              <input type="checkbox" name="is_new" value="1" title="新品" {if condition="isset($data.is_new) AND $data.is_new eq 1"}checked{/if}>
              <input type="hidden" name="is_hot" value="0">
              <input type="checkbox" name="is_hot" value="1" title="热销" {if condition="isset($data.is_hot) AND $data.is_hot eq 1"}checked{/if}>
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label">包邮</label>
            <div class="layui-input-block">
              <input type="radio" name="is_shipping" value="0" title="包邮" checked>
              <input type="radio" name="is_shipping" value="1" title="计件" {if condition="isset($data.is_shipping) AND $data.is_shipping eq 1"}checked{/if}>
              <input type="radio" name="is_shipping" value="2" title="计重" {if condition="isset($data.is_shipping) AND $data.is_shipping eq 2"}checked{/if}>
            </div>
          </div>
        </div>
        <!-- 其他信息 end-->
        <!-- 商品相册 start-->
        <div class="layui-tab-item">
          <div class="layui-form-item">
            <label class="layui-form-label">相册</label>
            <div class="layui-input-inline">
                <button type="button" class="layui-btn layui-btn-primary ajax-photos"><i class="fa fa-file-image-o"></i> 多图上传</button>
            </div>
            <div class="layui-form-mid layui-word-aux">允许多文件上传，不支持ie8/9</div>
          </div>
          {notempty name="$data.img"}
          {volist name='$data.img' id='v'}
          <div class="layui-form-item">
            <label class="layui-form-label">展示图{$i}</label>
            <div class="layui-input-inline">
                <img class="layui-upload-img" src="{$v}" width="90%">
                <input type="hidden" name="img[]" value="{$v}" autocomplete="off" readonly="" class="layui-input">
                <button type="button" class="layui-btn layui-btn-primary layui-btn-position delete-photo"><i class="fa fa-times-circle"></i></button>
            </div>
          </div>
          {/volist}
          {/notempty}
        </div>
        <!-- 商品相册 end-->
        <!-- 供应商 start-->
        <div class="layui-tab-item">
          <div class="layui-form-item">
            <label class="layui-form-label">供应商</label>
            <div class="layui-input-inline">
                <select name="supplier_id" lay-search="">
                    <option value="">请选择供应商</option>
                    {volist name="sup" id="v"}
                    <option value="{$v.id}" {if condition="isset($data) and $data.supplier_id eq $v.id"}selected{/if}>{$v.name}</option>
                    {/volist}
                </select>
            </div>
            <div class="layui-form-mid layui-word-aux">供应商为空时，店铺自营</div>
          </div>
        </div>
        <!-- 供应商 end-->
        <div class="layui-form-item">
          <div class="layui-input-block">
            <button class="layui-btn" lay-filter="i" lay-submit="">保存</button>
            <button class="layui-btn layui-btn-primary" type="reset">重置</button>
          </div>
        </div>
      </div>
  </div>
</form>
{/block}
{block name='js'}
{js href="__AD_LIBS__/ueditor/ueditor.config.js,__AD_LIBS__/ueditor/ueditor.all.min.js,__AD_LIBS__/ueditor/lang/zh-cn/zh-cn.js" /}
<script>
layui.use(['form'], function () {
  var $ = layui.jquery;
  var layer = layui.layer;
  var form = layui.form;
  UE.getEditor('editor',{
      initialFrameWidth :'auto',// 设置编辑器宽度
      initialFrameHeight:400,// 设置编辑器高度
      scaleEnabled:true
  });
  //选择
  form.on('select', function(data){
    if (data.value>0) {
        $.ajax({
        type:'POST',
        url:'{:url("sku_list")}',
        data:{"id":+data.value},
        success:function(data){
          $('#attr_id').html(data);
          layui.use('form', function() {
            var form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
            form.render();
          });
        }
      });
    }else{
      document.getElementById('attr_id').innerHTML = '<input type="checkbox" name="sku_id" value="0" checked>';
      // layer.msg('单规格商品');
    }
  });
});
</script>
{/block}